package com.yc.yyds.servlet;

import com.google.gson.Gson;
import com.yc.yyds.Bean.Result;
import com.yc.yyds.biz.BizException;
import com.yc.yyds.biz.QueryMovieBiz;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import java.util.Map;

@WebServlet(name = "UserQueryMovieServlet", value = "/UserQueryMovieServlet.s")
public class UserQueryMovieServlet extends HttpServlet {

    QueryMovieBiz biz = new QueryMovieBiz();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        //获取查询的字段名
        String currentPage = request.getParameter("currentPage");
        String moviename = request.getParameter("movienxame");
        String type = request.getParameter("type");
        String area = request.getParameter("area");
        String moviedate = request.getParameter("moviedate");
        System.out.println("currenPage = " + currentPage);
        int size = 16;
        int begin =size*(Integer.valueOf(currentPage)-1);

        //声明实体类
        Result result = null;
        PrintWriter out = response.getWriter();
        try {
            final Map<String, Object> data = biz.queryMovie(moviename, type, area, moviedate, begin, size);
            result = new Result(1,null,data);
            String json = new Gson().toJson(result);
            out.append(json);
        } catch (BizException e) {
            e.printStackTrace();
            result = new Result(0,e.getMessage(),null);
            String json = new Gson().toJson(result);
            out.append(json);
        }

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
